import 'package:flutter/material.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

class VideoRankItem extends StatelessWidget {
  final int index;
  final VideoModel? movie;

  const VideoRankItem({super.key, this.index = 0, this.movie});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        pushToVideoPage(videoModel: movie);
      },
      child: Container(
        height: 95,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              width: 168,
              height: 95,
              child: Stack(
                fit: StackFit.expand,
                children: [
                  NetworkImageLoader(
                    imageUrl: movie?.cover ?? '',
                    borderRadius: 8,
                  ),
                  Container(
                    alignment: Alignment.bottomCenter,
                    padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
                    child: Row(
                      children: [
                        Image.asset("eye_icon.webp".homePath, width: 16),
                        Text(
                          movie?.playCount?.humanizeFormat ?? '0',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 10,
                            height: 1.6,
                          ),
                        ),
                        Spacer(),
                        Text(
                          movie?.playTime?.timeMSFormat ?? "",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 10,
                            height: 1.6,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(width: 10),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Row(
                    children: [
                      Image.asset(rankImgPath(index), width: 24),
                      SizedBox(width: 4),
                      Text(
                        "NO.${index + 1}",
                        style: TextStyle(
                          color: rankColor(index),
                          fontSize: 14,
                        ),
                      ),
                    ],
                  ),
                  Text(
                    "${movie?.title ?? ''}\n",
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Color(0xE5FFFFFF),
                      fontSize: 12,
                      height: 1.5,
                    ),
                  ),
                  Row(
                    children: [
                      Image.asset(
                        "collect_start.webp".homePath,
                        width: 14,
                        height: 14,
                      ),
                      SizedBox(width: 5),
                      Text(
                        movie?.collectCount?.humanizeFormat ?? "0",
                        style: TextStyle(color: Color(0xff989898), fontSize: 12),
                      )
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

String rankImgPath(int index) {
  if (index < 4) {
    return "assets/images/home/rank_${index + 1}.webp";
  }
  return "assets/images/home/rank_5.webp";
}

Color rankColor(int index) {
  List<Color> colors = [
    Color(0xffFFD059),
    Color(0xffF24A71),
    Color(0xff5DCAE7),
    Color(0xffF28F76),
    Color(0xff525252),
  ];
  if (index < 4) {
    return colors[index];
  }
  return colors.last;
}
